<template>
	<el-dropdown size="medium" trigger="click" @command="handleUserCommand($event)" v-if="isExistDropdown">
		<el-button type="text">
			更多
			<i class="el-icon-arrow-down"></i>
		</el-button>
		<el-dropdown-menu slot="dropdown">
			<template v-if="data.del === '1'">
				<el-dropdown-item icon="sw-icon-user-banning" command="blockedAccount" v-hasPermi="authButton.banRecover">封禁账号</el-dropdown-item>
			</template>
			<template v-if="data.del === '2'">
				<el-dropdown-item icon="sw-icon-user-deblocked" command="recoverAccount" v-hasPermi="authButton.banRecover">恢复账号</el-dropdown-item>
			</template>
			<template v-if="data.del === '3'">
				<el-dropdown-item icon="sw-icon-user-audit" command="auditAccount" v-hasPermi="authButton.audit">审核用户</el-dropdown-item>
			</template>
			<el-dropdown-item icon="sw-icon-btn-passwd" command="updatePassword" v-hasPermi="authButton.passwd">更改密码</el-dropdown-item>
			<el-dropdown-item icon="sw-icon-role-manage" command="configRole" v-hasPermi="authButton.configRole">配置角色</el-dropdown-item>
		</el-dropdown-menu>
	</el-dropdown>
</template>

<script>
import lodash from 'lodash';
export default {
	props: {
		data: { type: Object, default: () => {} },
		authButton: { type: Object, default: () => {} }
	},
	computed: {
		isExistDropdown() {
			if (!lodash.isEmpty(this.authButton)) {
				if (!!this.authButton.banRecover && !!['1', '2'].some((n) => n === this.data.del)) {
					return true;
				}
				if (!!this.authButton.audit && this.data.del === '3') {
					return true;
				}
				if (!!this.authButton.passwd || !!this.authButton.configRole) {
					return true;
				}
			}
			return false;
		}
	},
	methods: {
		handleUserCommand(command) {
			this.$emit('command', command);
		}
	}
};
</script>

<style scoped></style>
